home *** CD-ROM | disk | FTP | other *** search
- ; TEST.ASM
- ; (c) 1990 by Roger A. Krupski
-
- page ,132
-
- bufsiz equ 1024*32 ;32k test buffer
-
- data STRUC
- handle dw ? ;handle
- time dw ? ;save time
- numbuf db 5 dup (?) ;output number buffer
- source db 256 dup (?) ;source filename
- param db 256 dup (?) ;time parameter
- total dw ? ;parsed megabytes
- buffer db bufsiz dup (?) ;read data buffer
- dsiz db ? ;total data size
- data ENDS
-
- code SEGMENT ;define CODE segment
- ASSUME cs:code,ds:code,es:code,ss:code
- ORG 0100h ;.COM starts here
-
- entry: cld ;insure autoincrement
- sub sp,dsiz ;reserve data area
- mov bp,sp ;bp points to data area
-
- lea di,[bp+0] ;point to data area
- xor al,al ;clear al
- mov cx,dsiz ;byte count
- rep stosb ;clear data area
-
- mov si,81h ;point to PSP command line
-
- call skip ;skip space(s)
- lea di,[bp+source] ;point to data area
- call copy ;get filename
-
- call skip ;skip space(s)
- lea di,[bp+param] ;point to data area
- call copy ;get megabytes
-
- lea si,[bp+param] ;point to number parameter
-
- parse: lodsb ;get a character
- cmp al,0 ;end of line?
- je cont ;yes, continue
- cmp al,'0' ;valid?
- jb error3 ;no
- cmp al,'9' ;valid?
- ja error3 ;no
- sub al,'0' ;yes, normalize
-
- push ax ;save parsed number
-
- mov al,byte ptr [bp+total] ;get current accumulator
- mov ah,10 ;load multiply factor
- mul ah ;multiply al by ah
- jc error3 ;exit if overflow
- mov byte ptr [bp+total],al ;store new number
- pop ax ;get parsed number
- add al,byte ptr [bp+total] ;add to accumulator
- jc error3 ;exit if overflow
- mov byte ptr [bp+total],al ;store new total
- jmp parse ;get more
-
- error3: mov cx,siz5 ;size of message
- lea dx,msg5 ;point to message
- call print ;print it
- jmp exit ;and leave
-
- cont: lea dx,[bp+source] ;point to filename
- mov ax,3d00h ;dos "open", read-only mode
- int 21h ;call DOS
- jnc ok1 ;go if ok
-
- mov cx,siz1 ;size of message
- lea dx,msg1 ;point to message
- call print ;print error message
- jmp exit ;and leave
-
- ok1: mov [bp+handle],ax ;save handle
-
- mov cx,siz6 ;message size
- lea dx,msg6 ;point to message
- call print ;print it
-
- call getime ;get time
- mov [bp+time],dx ;save start time
-
- mov cx,[bp+total] ;times to do loop
- cmp cx,0 ;bad number?
- je error3 ;yes, exit
-
- mov ax,cx ;copy megabytes to ax
- mov dx,32 ;32*32K=1 meg
- mul dx ;multiply ax by dx
- mov cx,ax ;copy new number to cx
-
- speed: call read ;read 32k
- jc error2 ;exit if error
- loop speed ;go again
-
- call getime ;get ending time
- mov ax,[bp+time] ;get start time
- sub dx,ax ;subtract start from end
- jns ok ;go if not looped around
-
- add dx,60*60 ;correct negative time
-
- ok: push dx ;save test time
- mov cx,2 ;2 bytes
- lea dx,msg1 ;point to cr/lf
- call print ;print a cr/lf
-
- mov dx,[bp+total] ;get test time
- call ascii ;convert time to ascii
- call numout ;print test time
-
- mov cx,siz3 ;message size
- lea dx,msg3 ;point to message
- call print ;print it
-
- pop dx ;get test seconds
- call ascii ;convert seconds to ascii
- call numout ;print number
-
- mov cx,siz4 ;message size
- lea dx,msg4 ;point to message
- call print ;print it
- jmp exit ;exit to dos
-
- error2: mov cx,siz2 ;size of message
- lea dx,msg2 ;point to message
- call print ;print it
- jmp exit ;and leave
-
-
- ascii: mov al,"0" ;load ascii 00
- mov cx,5 ;number of ascii places
- push cx ;save count
- lea di,[bp+numbuf] ;point to number buffer
- rep stosb ;store ascii zero
-
- lea si,nums ;point to number field
- lea di,[bp+numbuf] ;point to number buffer
-
- pop cx ;get loop counter
-
- loop1: sub dx,[si] ;subtract 10's place
- js loop2 ;exit if done
- mov al,[di] ;get ascii number
- inc al ;bump it
- mov [di],al ;store it back
- jmp loop1 ;go again
-
- loop2: add dx,[si] ;add number back in
- add si,2 ;bump si
- inc di ;bump di
- loop loop1 ;do next number
- ret ;return
-
-
- numout: lea si,[bp+numbuf] ;point to number buffer
- mov dx,si ;copy to dx
- mov cx,5 ;max bytes to write
- num2: cmp cx,1 ;last zero?
- je num3 ;yes, keep it
- lodsb ;get a byte from buffer
- cmp al,"0" ;leading zero?
- jne num3 ;no, print it
- inc dx ;yes, point to next
- loop num2 ;go again
- num3: jmp print ;print & return
-
-
- read: push ax ;
- push bx ;
- push cx ;
- push dx ;save registers
-
- lea dx,[bp+buffer] ;point to buffer
- mov bx,[bp+handle] ;get file handle
- mov ah,3fh ;dos "read"
- mov cx,bufsiz ;get bytes to read
- int 21h ;call dos
- jc err ;error, exit
-
- cmp ax,bufsiz ;file big enough?
- je okay ;yes
- stc ;no, set carry=error
- jmp err ;and exit
-
- okay: mov cx,0 ;offset 0
- mov dx,0 ;offset 0
- mov al,0 ;reset file pointer
- mov ah,42h ;dos "seek"
- mov bx,[bp+handle] ;get handle
- int 21h ;call dos
-
- err: pop dx ;
- pop cx ;
- pop bx ;
- pop ax ;restore registers
- ret ;return
-
- getime: mov ah,2ch ;dos "get time"
- int 21h ;call dos
- xor ax,ax ;clear ax
- push dx ;save dx
- mov al,cl ;copy minutes into al
- mov dx,60 ;seconds per minute
- mul dx ;multiply ax by dx
- pop dx ;restore seconds
- xor dl,dl ;drop centiseconds
- xchg dh,dl ;swap seconds and centiseconds
- add dx,ax ;add minutes to seconds
- ret ;dx=absolute seconds, return
-
- exit: mov bx,[bp+handle] ;get file handle
- cmp bx,0 ;no file opened?
- je exit2 ;no, leave
- mov ah,3eh ;dos "close file"
- int 21h ;close file
- exit2: add sp,dsiz ;de-allocate data area
- mov ax,4c00h ;dos "terminate"
- int 21h ;exit to dos
-
- skip: lodsb ;get a byte
- cmp al," " ;leading space?
- je skip ;yes, skip it
- dec si ;no, fix si
- ret ;return
-
- copy: lodsb ;get a byte
- cmp al," " ;space?
- je copy3 ;yes, exit
- cmp al,0dh ;end of line?
- je copy3 ;yes, exit
- cmp al,"a" ;lowercase?
- jb copy2 ;no, keep it
- cmp al,"z" ;lowercase?
- ja copy2 ;no, keep it
- xor al,20h ;yes, flip case bit
- copy2: stosb ;no, store byte
- jmp copy ;continue
- copy3: dec si ;fix si
- ret ;return
-
- print: mov ah,40h ;dos "write"
- mov bx,1 ;standard out
- int 21h ;call dos
- ret ;return
-
- nums dw 10000
- dw 1000
- dw 100
- dw 10
- dw 1
-
- msg1 db 13,10
- db "Unable to open file."
- db 13,10
- siz1 equ $-msg1
-
- msg2 db 13,10
- db "Test file must be 32768 bytes or larger."
- db 13,10
- siz2 equ $-msg2
-
- msg3 db " megabyte(s) in "
- siz3 equ $-msg3
-
- msg4 db " second(s)."
- db 13,10
- siz4 equ $-msg4
-
- msg5 db 13,10
- db "Parameter error: Must be from 1 to 255 megabytes."
- db 13,10
- siz5 equ $-msg5
-
- msg6 db 13,10
- db "Timing, please wait..."
- db 13,10
- siz6 equ $-msg6
-
- code ENDS
- END entry
-